﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
using DBControl;

namespace SellerProject
{
    public partial class marketing_test
    {
        public string sessionkey { get; set; }
        public string tagid { get; set; }

        private static ITopClient client = new DefaultTopClient(SystemLib.appurl, "12268933", "5c8fc265d41463b42f222d91f9f55fdf");


        public Boolean Market_tag_add(string tagname, string tagdescription)
        {
            try
            {
                MarketingTagAddRequest req = new MarketingTagAddRequest();
                req.TagName = tagname;
                req.Description = tagdescription;
                MarketingTagAddResponse response = client.Execute(req, sessionkey);

                tagid = response.UserTag.TagId.ToString();
                return response.IsSuccess;
            }
            catch
            {
                return false;
            }
        }

        public Boolean Targetuser_add(int tagid, string usernick)
        {
            try
            {
                MarketingTaguserAddRequest req = new MarketingTaguserAddRequest();
                req.TagId = tagid;
                req.Nick = usernick;
                MarketingTaguserAddResponse response = client.Execute(req, sessionkey);

                return response.IsSuccess;
            }
            catch
            {
                return false;
            }
        }

        public Boolean Promotion_add(string numid, string tag_id)
        {
            try
            {
                MarketingPromotionAddRequest req = new MarketingPromotionAddRequest();
                req.NumIids = "9604285167";
                req.DiscountType = "DISCOUNT";
                req.DiscountValue = "8.5";
                DateTime dateTime = DateTime.Parse("2011-06-07 00:00:00");
                req.StartDate = dateTime;
                DateTime dateTime1 = DateTime.Parse("2011-06-07 12:45:59");
                req.EndDate = dateTime1;
                //req.PromotionTitle = "";
                req.TagId = long.Parse(tag_id);
                MarketingPromotionAddResponse response = client.Execute(req, sessionkey);

                return response.IsSuccess;
            }
            catch
            {
                return false;
            }
        }

        public void check()
        {
            MarketingPromotionsGetRequest req = new MarketingPromotionsGetRequest();
            //req.Status = "ACTIVE";
            req.Fields = "promotion_id, promotion_title, item_id";
            req.NumIid = "9604285167";
            MarketingPromotionsGetResponse response = client.Execute(req, sessionkey);

        }

        public void taggets()
        {
            MarketingTagsGetRequest req = new MarketingTagsGetRequest();
            req.Fields = "tag_id,tag_name";
            MarketingTagsGetResponse response = client.Execute(req, sessionkey);
        }

        public string checkusertag()
        {
            MarketingTagsGetRequest req = new MarketingTagsGetRequest();
            req.Fields = "tag_id,tag_name";
            MarketingTagsGetResponse response = client.Execute(req, sessionkey);

            return response.UserTags[0].TagId.ToString();
        }

        public void checkpromotion(string session)
        {
            MarketingPromotionsGetRequest req = new MarketingPromotionsGetRequest();
            //req.Status = "ACTIVE";
            req.Fields = "promotion_id, promotion_title, item_id,start_date,end_date,discount_value,status";
            req.TagId = 663413;
            req.NumIid = "9604285167";
            MarketingPromotionsGetResponse response = client.Execute(req, session);
        }
    }
}



//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using Top.Api;
//using Top.Api.Domain;
//using Top.Api.Parser;
//using Top.Api.Request;
//using Top.Api.Response;
//using Top.Api.Util;
//using DBControl;

//namespace SellerProject
//{
//    public class marketing_test
//    {
//        
//    }
//}